package game_engine;

import game_engine.core.GECore;
import game_engine.core.GameStage;
import game_engine.display.GEWindowOGL;
import game_engine.display.Texture;

import java.awt.Color;
import java.awt.Dimension;

import org.newdawn.slick.TrueTypeFont;

public class GameEngine {
	
	private GECore core;
	private GEWindowOGL window;
	
	public static Dimension resolution = null;
	
	private static GameEngine instance;
	
	
	private GameEngine() {
		core = new GECore();
		window = new GEWindowOGL(core);
	}
	
	public void start() {
		if(resolution != null) {
			core.start();
			window.start();
			while(!window.isLoaded()) {
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		} else {
			System.err.println("You must a resolution to start the game engine by using method GameEngine.setResolution()");
		}
	}
	
	public void setGameStage(GameStage stage) {
		core.setGameStage(stage);
	}
	
	public void setResolution(Dimension resolution) {
		GameEngine.resolution = resolution;
		window.setResolution(resolution);
	}
	
	public void setTitle(String title) {
		window.setTitle(title);
	}
	
	public static GameEngine getInstance() {
		if(instance==null) instance = new GameEngine();
		return instance;
	}
	
	public Texture getTexture(String image, Color transColor) {
		return window.getTexture(image, transColor);
	}
	
	public void addTextureToLoad(String image, Color transColor) {
		core.addTextureToLoad(image, transColor);
	}
	
	public void addFontToLoad(String id, String fontName, int fontSize) {
		core.addFontToLoad(id, fontName, fontSize);
	}
	
	public TrueTypeFont getFont(String id) {
		return window.getFont(id);
	}
	
	public boolean isAllFontLoaded() {
		return core.isAllFontLoaded();
	}
	
	public boolean isAllTextureLoaded() {
		return core.isAllTextureLoaded();
	}
	
	public void stop() {
		core.stop();
		window.stop();
	}
	
	public boolean isRunning() {
		return core.isRunning();
	}

}
